#include "NaTools.hpp"
using namespace std;

const double t[6]={0,3,5,8,13};
const double dis[6]={0,225,383,623,993,-1};
const double speed[6]={75,77,80,74,72,-1};
vector<double> time_dat;

const double N = 10;

class T:public func{
	double operator()(double x){
		int i=0;
		for(i=0;i<5;i++) if(x==t[i]) break;
		return dis[i];
	}
	double deriv(double x,int p){
		int i=0;
		for(i=0;i<5;i++) if(x==t[i]) break;
		return speed[i];
	}
};

void init(){
	for(int i=0;i<5;i++){
		time_dat.push_back(t[i]);
		time_dat.push_back(t[i]);
	}
}

void check(polynomial& Q){
	Q.print();
	cout << "The value at t[i]:" << endl;
	for(int i=0;i<5;i++) cout << Q(t[i]) << " "; cout << endl;
	cout << "The deriv at t[i]:" << endl;
	for(int i=0;i<5;i++) cout << Q.diff(t[i]) << " "; cout << endl;
}

int main(){
	init();
	T data;
	Hermite_inter h(data,time_dat);
	polynomial Q = h.stdrize();
	// Q.latex();
	// check(Q);
	double step = (t[4]-t[0])/N;
	double tl = 0;
	double maxspeed =0;
	cout << "The answer for A):" << endl;
	cout << "The position and speed at 10s are " << Q(10) << "(feet) and " << Q.diff(10) << "(f/s)." <<endl;
	cout << "The answer for B):" << endl;
	for(int i=0;i<=N;i++){
		double ans = Q.diff(tl);
		maxspeed = maxspeed<ans ? ans : maxspeed;
		if(ans>81){
			cout << "The speed at time " << tl << " is " << ans << " ,which exceeds 81 f/s." <<endl;
		}
		tl += step;
	}
}